<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="com.erp.util.Page"%>
<%@page import="com.erp.po.Products"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../../assets/css/maincss.css" rel="stylesheet" />
<link href="../../assets/css/but.css" rel="stylesheet" />
</head>
<!-- Bootstrap -->
<link href="${pageContext.request.contextPath}/javascript/bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/javascript/jQuery-1.12.4.js"></script>
<script src="${pageContext.request.contextPath}/javascript/bootstrap/js/bootstrap.js"></script>
<body>
<h3>产品管理</h3>
<a href="seachProduct.jsp" class="btn btn-default">查询产品</a>
<br />
<table class="table table-hover" style="text-align: center;" >
	
	<tr>
		<td>商品id</td>
		<td>商品名称</td>
		<td>商品进价</td>
		<td>商品数量</td>
		<td>商品售价</td>
		<td>进货时间</td>
		<td>商品类别</td>
		<td>供应商</td>
		<td>操作</td>
	</tr>
	<c:forEach items="${page.list}" var="pro">
		<tr>
			<td>${pro.productId}</td>
			<td>${pro.productName}</td>
			<td>${pro.incomePrice}</td>
			<td>${pro.quantity}</td>
			<td>${pro.salesPrice}</td>
			<td>${pro.incomeTime}</td>
			<td>${pro.categorys.categoryName}</td>
			<td>${pro.providers.providerName}</td>
			<td>
				<button onclick="editProductById(${pro.productId})" class="btn btn-success btn-sm">修 改</button>
				&nbsp;
				<button onclick="return delProductById(${pro.productId})" class="btn btn-danger btn-sm">删 除</button>
			</td>
		</tr>
	</c:forEach>
	
	
<%-- 	<%
		for(Products p : list){
	%>
		<tr>
			<td><%= p.getProductId()%></td>
			<td><%= p.getProductName()%></td>
			<td><%= p.getIncomePrice()%></td>
			<td><%= p.getQuantity()%></td>
			<td><%= p.getSalesPrice()%></td>
			<td><%= p.getIncomeTime()%></td>
			<td><%= p.getCategorys().getCategoryName()%></td>
			<td><%= p.getProviders().getProviderName()%></td>
			<td>
				<a href="###" onclick="delProductById(<%= p.getProductId()%>)">删除</a>
				&nbsp;&nbsp;
				<a href="###" onclick="editProductById(<%= p.getProductId()%>)">修改</a>
			</td>
		</tr>
	<%			
		}
	%> --%>
	
	<tr align="center">
		<td colspan="9">
			<%-- <%
				if(pages.getCurrentPage() != 1){
			%>
					<a href="productServlet?op=showProductByPage&currentPage=<%=pages.upPage() %>&pageSize=5">[上一页]</a>
			<%
				}
			%>	 --%>
			<c:if test="${page.currentPage != 1}">
				<a href="productServlet?op=showProductByPage&currentPage=${page.upPage()}&pageSize=5">[上一页]</a>
			</c:if>
			
			&nbsp;&nbsp;&nbsp;&nbsp;
			当前第${page.currentPage}页
			&nbsp;&nbsp;
			共${page.total}条数据
			&nbsp;&nbsp;
			共${page.totalPages()}页
			&nbsp;&nbsp;&nbsp;&nbsp;
			<c:if test="${page.currentPage != page.totalPages()}">
				<a href="productServlet?op=showProductByPage&currentPage=${page.nextPage()}&pageSize=5">[下一页]</a>
			</c:if>
			
			<%-- <%
				if(pages.getCurrentPage() != pages.totalPages()){
			%>
					<a href="productServlet?op=showProductByPage&currentPage=<%=pages.nextPage() %>&pageSize=5">[下一页]</a>
			<%
				}
			%>	 --%>
		</td>
	</tr>


</table>

</body>

<script type="text/javascript">
	function editProductById(id){
		location.href='productServlet?op=readyEditProductById&id='+id;
	}
	
	function delProductById(id){
		var msg = "确定删除该条数据?";
		if(confirm(msg) == true){
			location.href='productServlet?op=removeProductByproId&id='+id;
			return true;
		} else {
			return false;	
		}
		
	}
	
	function addProductBut(){
		location.href='productServlet?op=readyAddProduct';
	}


</script>

</html>